const keys = [
    "0",
    "1",
    "2",
    "3",
    "4",
    "5",
    "6",
    "7",
    "8",
    "9",
    "0",
    "a",
    "b",
    "c",
    "d",
    "e",
    "f",
    "g",
    "h",
    "i",
    "j",
    "k",
    "l",
    "m",
    "n",
    "o",
    "p",
    "q",
    "r",
    "s",
    "t",
    "u",
    "v",
    "w",
    "x",
    "y",
    "z",
];

$(() => {
    let tabIds = [];

    chrome.tabs.query({ currentWindow: true }, (tabs) => {
        for (let [idx, t] of tabs.entries()) {
            let idxStr = idx;
            if (idx >= 10) {
                idxStr = String.fromCharCode("A".charCodeAt(0) + idx - 10);
            }
            $("#list").append(
                $(`<li class="tab-item">
            <span>${idxStr}</span>
            <img class="icon-img" src="${t.favIconUrl}"/>
            <div class="item-title">${t.title}</div>
            </li>`)
            );
            tabIds.push(t.id);
        }
    });

    $(document).on("keydown", (e) => {
        for (let [idx, k] of keys.entries()) {
            if (e.key == k) {
                $("#list").append(e.key);
                chrome.tabs.update(tabIds[idx], { active: true });
                break;
            }
        }
    });
});
